

$(function () {
    var addFlag = permissions.admin_sysgrayitem_add
    var editFlag = permissions.admin_sysgrayitem_edit
    var delFlag = permissions.admin_sysgrayitem_del
    var setFlag = permissions.admin_sysfrontgray_add_edit
    var delFrontFlag = permissions.admin_sysfrontgray_del
    //没有新增权限的话删除新增按钮
    if (!addFlag) {
        $('#addBtn').remove()
    }

    var options = {
        url: api + "/admin/sysgrayitem/page",
        updateUrl: "/pages/sysadm/gray/grayEdit",
        removeUrl: api + "/admin/sysgrayitem/{id}",
        createTime: false,
        modalName: "灰度节点",
        columns: [
            {
                title: "序号",
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
            {
                field: 'serverIp',
                title: 'IP地址'
            },
            {
                field: 'serverPort',
                title: '端口'
            },
            {
                field: 'springApplicationName',
                title: '服务名'
            },
            {
                field: 'createTime',
                title: '创建时间',
                sortable: true,
            },
            {
                field: 'remark',
                title: '备注'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    if (editFlag) {
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    }
                    if (delFlag) {
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                    }
                    if (setFlag) {
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="setRelation(\'' + row.id + '\',\'' + row.springApplicationName + '\')"><i class="fa fa-cog"></i>设置</a> ');
                    }
                    actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="relationList(\'' + row.id + '\',\'' + row.springApplicationName + '\')"><i class="fa fa-heartbeat"></i>关系</a> ');

                    return actions.join('');
                }
            }]
    };
    $.table.init(options);
});

function setRelation(id,name) {
    var url = '/pages/sysadm/gray/graySet?oper=add&grayId=' + id + '&serveName='+ name;
    $.modal.open("设置灰度规则", url);
}

function relationList(id, name) {
    var url = '/pages/sysadm/gray/grayRelation?grayId=' + id + '&serveName='+ name;
    $.modal.openview("灰度规则", url);
}